package thread.cf;

import java.util.concurrent.CompletableFuture;

public class CompletableFutureDemo1 {

    public static void main(String[] args) throws InterruptedException {

        CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("任务1执行完成" + Thread.currentThread().getName());
            return "Task1";
        });
        CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("任务2执行完成" + Thread.currentThread().getName());
            return "Task2";
        });

        future1.thenApplyAsync(s -> {
            System.out.println("Future1新开任务线程: " + Thread.currentThread().getName());
            return s + "-processed";
        });

        future2.thenApplyAsync(s -> {
            System.out.println("Future2新开任务线程: " + Thread.currentThread().getName());
            return s + "-processed";
        });
        Thread.sleep(5);

    }
}
